package com.heima.thread.test;

class StringUtils
{
    public static String[] spl(String str, String check){
        String[] ans = new String[1000];
        int cnt = 0;
        String now = "";

        for(int i=0;i<str.length();++i)
        {
            int flag = 0;
            int nexti = 0;
            if(str.charAt(i) == check.charAt(0)){
                flag = 0;
                for(int j1=i, j2=0;j1<str.length() && j2<check.length();++j1, ++j2){
                    if(str.charAt(j1) != check.charAt(j2)){
                        break;
                    }
                    flag = j2;
                    nexti = j1;
                }
            }
            if(flag == check.length()-1){
                ans[cnt++] = now;
                now = "";
                i = nexti;
            }else {
                now += str.charAt(i);
            }
        }
        if(!now.equals("")){
            ans[cnt++] = now;
        }
        return ans;
    }
    public static String comb(String[] str, String check){
        String ans = "";
        for(int i=0;i<str.length;++i)
        {
            ans += str[i];
            if(i == str.length-1){
                break;
            }
            ans += check;
        }
        return ans;
    }
}

public class test2 {

    public static void main(String[] args) {

        String[] strs = {"ab", "2"};
        System.out.println(StringUtils.comb(strs, "&&"));

        String str = "ab&&2";
        String[] spls = StringUtils.spl(str, "&&");
        for (String spl : spls) {
            if(spl == null){
                break;
            }
            System.out.println(spl);
        }
    }
}
